home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / FFT and Complex Numbers Library / FFTLibrary.sit / FFT library ƒ / FourierUtilities.cp < prev    next >
Text File  |  1995-01-15  |  906b  |  53 lines

  1. //
  2. //    File: FourierUtilities.cp
  3. //    Copyright ⌐1994-1995 James Wilson
  4. //    All rights reserved.
  5. //    
  6. //    This document contains the bit-reversing and power utility functions
  7. //    used by the FFT and IFFT functions.
  8.  
  9. #ifndef __FFT__
  10. #include "FFT.h"
  11. #endif
  12.  
  13. long BitReverse(const long theNum, const long nu)
  14. {
  15.     long                    index, temp1, temp2, k;
  16.     
  17.     temp1 = theNum;
  18.     k = 0L;
  19.     
  20.     for(index = 1L; index <= nu; index++)
  21.     {
  22.         temp2 = temp1 / 2L;
  23.         
  24.         // Do NOT change to "k *= 2L + (temp1 - 2L * temp2)"! The right
  25.         // side of the expression is evaluated first and the result is
  26.         // k * (2L + (temp1 - 2L * temp2)), not what you wanted!!
  27.         
  28.         k = k * 2L + (temp1 - 2L * temp2);
  29.         temp1 = temp2;
  30.     }
  31.     
  32.     return k;
  33. }
  34.  
  35. long LongPower(const long base, const long exp)
  36. {
  37.     long                        index, k, tempExp;
  38.     
  39.     k = 1L;
  40.     
  41.     if(exp != 0L)
  42.     {
  43.         k = base;
  44.         
  45.         for(index = 1L; index < exp; index++)
  46.         {
  47.             k *= base;
  48.         }
  49.     }
  50.     
  51.     return k;
  52. }
  53.